﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Manage_registrationList : System.Web.UI.Page
{
    BLL.RegistrationBll regBll = new BLL.RegistrationBll();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
            ShowPageFooter();
        }
    }

    private void BindData()
    {
        DataTable table = regBll.GetAllRegistration();
        grd_Registration.DataSource = table;
        grd_Registration.DataBind();

        for (int i = 0; i < grd_Registration.Rows.Count; i++)
        {
            int isReged = int.Parse(grd_Registration.Rows[i].Cells[10].Text.ToString());
            if (isReged == 1)
            {
                LinkButton luqu = (LinkButton)grd_Registration.Rows[i].FindControl("btn_Luqu");
                luqu.Text = "已录取";
                luqu.Enabled = false;
            }
        }

        //显示总条数
        Label lblCount = (Label)grd_Registration.BottomPagerRow.FindControl("lbl_Count");
        lblCount.Text = table.Rows.Count.ToString();
    }


    protected void grd_Registration_SelectedIndexChanged(object sender, EventArgs e)
    {
        int id = int.Parse(grd_Registration.Rows[grd_Registration.SelectedIndex].Cells[0].Text.ToString());

        //Response.Write(id);
        Response.Redirect("luqu.aspx?id="+id);
    }


    protected void grd_Registration_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grd_Registration.PageIndex = e.NewPageIndex;

        BindData();
        ShowPageFooter();
    }

    private void ShowPageFooter()
    {
        //给显示分页TextBox赋值
        TextBox txtPageIndex = (TextBox)grd_Registration.BottomPagerRow.FindControl("txt_PageIndex");
        txtPageIndex.Text = (grd_Registration.PageIndex + 1).ToString();
    }

    protected void grd_Registration_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Go")
        {
            try
            {
                TextBox txtPageIndex = (TextBox)grd_Registration.BottomPagerRow.FindControl("txt_PageIndex");
                int index = Int32.Parse(txtPageIndex.Text);
                GridViewPageEventArgs ea = new GridViewPageEventArgs(index - 1);
                grd_Registration_PageIndexChanging(null, ea);
            }
            catch
            {

            }
        }
    }
    protected void grd_Registration_DataBinding(object sender, EventArgs e)
    {
        //LinkButton luqu = (LinkButton)
        //int isReged = grd_Registration.Rows
    }
    protected void grd_Registration_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //LinkButton luqu = (LinkButton)e.Row.TemplateControl.FindControl("btn_Luqu");
        //luqu.Text = "eoe";
        //int isReged = grd_Registration.Rows[]
    }
}
